#pragma once

#include "base/event_loop.h"
#include "base/xhead.h"

#include <list>

#include <rtc_base/sds.h>
#include <rtc_base/slice.h>

namespace xrtc {

class TcpConnection {
public:

    enum {
        STATE_HEAD = 0,
        STATE_BODY = 1
    };

    TcpConnection(int fd);
    ~TcpConnection();

public:
    int m_fd;
    char m_ip[64];
    int m_port;

    IOWatcher* m_io_watcher = nullptr;
    TimerWatcher* m_timer_watcher = nullptr;

    sds m_querybuf;
    size_t m_bytes_expected = XHEAD_SIZE;
    size_t m_bytes_processed = 0;

    int m_current_state = STATE_HEAD;
    unsigned long m_last_interaction = 0;

    std::list<rtc::Slice> m_reply_list;
    size_t m_cur_resp_pos = 0;
};
    
} // namespace xrtc
